import 'package:equatable/equatable.dart';

/// 用户模型
/// 使用Equatable进行对象比较和状态管理
class UserModel extends Equatable {
  /// 用户ID
  final String id;

  /// 用户名
  final String username;

  /// 密码
  final String password;

  /// 昵称
  final String nickname;

  /// 头像
  final String avatar;

  /// 个性签名
  final String signature;

  const UserModel({
    required this.id,
    required this.username,
    required this.password,
    required this.nickname,
    required this.avatar,
    required this.signature,
  });

  /// 从JSON创建用户对象
  factory UserModel.fromJson(Map<String, dynamic> json) {
    return UserModel(
      id: json['id'] as String,
      username: json['username'] as String,
      password: json['password'] as String,
      nickname: json['nickname'] as String,
      avatar: json['avatar'] as String,
      signature: json['signature'] as String,
    );
  }

  /// 转换为JSON
  Map<String, dynamic> toJson() {
    return {
      'id': id,
      'username': username,
      'password': password,
      'nickname': nickname,
      'avatar': avatar,
      'signature': signature,
    };
  }

  /// 复制并更新用户对象
  UserModel copyWith({
    String? id,
    String? username,
    String? password,
    String? nickname,
    String? avatar,
    String? signature,
  }) {
    return UserModel(
      id: id ?? this.id,
      username: username ?? this.username,
      password: password ?? this.password,
      nickname: nickname ?? this.nickname,
      avatar: avatar ?? this.avatar,
      signature: signature ?? this.signature,
    );
  }

  @override
  List<Object?> get props => [
    id,
    username,
    password,
    nickname,
    avatar,
    signature,
  ];

  @override
  String toString() {
    return 'UserModel(id: $id, username: $username, nickname: $nickname, avatar: $avatar, signature: $signature)';
  }
}
